﻿using System;
using System.Linq;
using System.Linq.Expressions;
using Microsoft.WindowsAzure.StorageClient;
using System.Collections.Generic;
using AntsCode.StorageClientExtensions.Helpers;

namespace AntsCode.StorageClientExtensions.QueryHandlers
{
    /// <summary>
    /// Handles a First or FirstOrDefault query
    /// </summary>
    /// <typeparam name="T">The source type.</typeparam>
    internal class FirstQueryHandler<T> : QueryHandler
    {
        public FirstQueryHandler(IQueryable<T> data, ContinuationToken continuationToken, bool allowDefault)
            : base(data, continuationToken)
        {
            if (data != null)
            {
                if (allowDefault)
                {
                    this.Data = data.FirstOrDefault();
                }
                else
                {
                    this.Data = data.First();
                }
            }
        }
    }
}
